package com.youlu.campus.service.config.impl;

import com.youlu.campus.entity.OuterAppUrlConfig;
import com.youlu.campus.service.config.OuterAppUrlConfigService;
import lombok.extern.slf4j.Slf4j;
import org.apache.commons.collections4.CollectionUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.mongodb.core.query.Criteria;
import org.springframework.data.mongodb.core.query.Query;
import org.springframework.stereotype.Service;

import java.util.List;

@Slf4j
@Service
public class OuterAppUrlConfigServiceImpl implements OuterAppUrlConfigService {
    @Autowired
    private MongoTemplate mongoTemplate;

    @Override
    public List<OuterAppUrlConfig> find( String url, String method) {
        Query q = new Query();
        q.addCriteria(Criteria.where("url").is(url).
                and("method").is(method));
        return mongoTemplate.find(q, OuterAppUrlConfig.class);
    }

    @Override
    public boolean exist( String url, String method) {
        List<OuterAppUrlConfig> datas = this.find( url, method);
        if (CollectionUtils.isEmpty(datas)) {
            return false;
        }
        return true;
    }
}
